import 'package:flutter/material.dart';
// import 'package:date_format/date_format.dart';

class FormAll extends StatefulWidget {
  FormAll({Key key}) : super(key: key);
  @override
  _FormAllState createState() => _FormAllState();
}

class _FormAllState extends State<FormAll> {
  int _sex = 0;
  List likeList = [
    {'name': '吃饭', 'value': 0, 'selected': false},
    {'name': '睡觉', 'value': 1, 'selected': false},
    {'name': '洗澡', 'value': 2, 'selected': false},
  ];
  // String
  TextEditingController _uname = TextEditingController();
  TextEditingController _desc = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('表单登记系统'),
      ),
      body: Container(
          padding: EdgeInsets.all(10),
          child: ListView(
            children: [
              TextField(
                onChanged: (v) {
                  print(v);
                },
                controller: this._uname,
                decoration: InputDecoration(hintText: '输入您的姓名'),
              ),
              SizedBox(height: 10),
              Row(
                children: [
                  // Expanded(child: T)
                  Text('性别:'),
                  SizedBox(width: 10),
                  Radio(value: 0, groupValue: this._sex, onChanged: _setSex),
                  Text('男'),
                  SizedBox(width: 10),
                  Radio(value: 1, groupValue: this._sex, onChanged: _setSex),
                  Text('女'),
                ],
              ),
              SizedBox(height: 10),
              Row(
                children: this._getLikeWidget(),
              ),
              SizedBox(height: 10),
              TextField(
                maxLines: 3,
                controller: this._desc,
                decoration: InputDecoration(
                    border: OutlineInputBorder(),
                    labelText: '自我介绍',
                    hintText: '请输入自我接受'),
              ),
              SizedBox(height: 20),
              Container(
                width: double.infinity,
                child: RaisedButton(
                  onPressed: () {},
                  child: Text('提交'),
                  color: Colors.blue,
                  textColor: Colors.white,
                ),
              )
            ],
          )),
    );
  }

  _setSex(v) {
    this.setState(() {
      this._sex = v;
    });
  }

  List<Widget> _getLikeWidget() {
    // List wid = this.likeList.map((e) {
    //   // return  Container();
    // }).toList();
    List<Widget> wid = [Text('爱好:')];
    for (var i = 0; i < this.likeList.length; i++) {
      wid.addAll([
        SizedBox(width: 10),
        Checkbox(
            value: this.likeList[i]['selected'],
            onChanged: (v) {
              setState(() {
                this.likeList[i]['selected'] = v;
              });
            }),
        Text(this.likeList[i]['name']),
      ]);
    }

    return wid;
  }
}
